package yao.guava.optional;

/**
 * 找到一个人的国家
 * @author chenyao
 *
 */
public class PersonMain {
	public static void main(String[] args) {
	}
	
	private Country getCountryOfOld(Person p) {
		Place place = p.getPlace();
		if (place != null) {
		 City city = place.getCity();
		 if (city != null) {
		   Province province = city.getProvince();
		   if (province != null) {
		     return province.getCountry();
		   }
		 }
		}
		return null;
		
	}
	/*public static void testOfNew(Person p) {
		Optional<Person> fromNullable = Optional.fromNullable(p);
		Person person = fromNullable.get();
		Function place = new Function<Optional<Place>, Optional<City>>() {
				@Override
				public Optional<City> apply(Optional<Place> input) {
					if(input.isPresent()) {
						return Optional.of(input.get().getCity());
					}
				}		
			};
		
		System.out.println(person);
	}
	
	Function<Optional<?>, Object> f = new Function<Optional<?>, Object>() {
		@Override
		public Object apply(Optional<?> input) {
			if(input.isPresent()) {
				return input.get();
			}
			return Optional.absent();
		}		
	};*/
	
	
	
	
	
	
	
	
	
}
